package com.gfxy.modules.items.service.impl;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.gfxy.modules.items.entity.Jnds;
import com.gfxy.modules.items.entity.teachingresult.TeachingResultContent;
import com.gfxy.modules.items.mapper.JndsMapper;
import com.gfxy.modules.items.service.IJndsService;
import com.gfxy.modules.items.vo.*;
import com.gfxy.modules.excel.ExcelUtil;
import org.apache.poi.ss.usermodel.Row;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

/**
 * @Description: 技能大赛
 * @Author: jeecg-boot
 * @Date:   2021-10-03
 * @Version: V1.0
 */
@Service
public class JndsServiceImpl extends AbstractProjectServiceImpl<JndsMapper, Jnds> implements IJndsService {
	protected int memberCellNum = 5;

	private int translateClassess(String classess){
		if(classess == null || classess.equals("")){
			return 0;
		} else if(classess.equals("国家级")){
			return 1;
		} else if(classess.equals("省级")){
			return 2;
		}else {
			return 0;
		}
	}

	private int translateAward(String award){
		if(award == null || award.equals("")){
			return 0;
		} else if(award.equals("一等奖")){
			return 1;
		} else if(award.equals("二等奖")){
			return 2;
		} else if(award.equals("三等奖")){
			return 3;
		} else {
			return 0;
		}
	}
	protected String[] getMemberArray(Row row) {
		String nameStrs = ExcelUtil.formatCell(row.getCell(memberCellNum));
		return nameStrs.split(memberNameSeparator);
	}
	private int translateCategories(String categories){
		if(categories == null || categories.equals("")){
			return 0;
		} else if(categories.equals("A类大赛")){
			return 1;
		} else if(categories.equals("B类大赛")){
			return 2;
		}else {
			return 0;
		}
	}

	@Override
	protected void pass(String id, String isPass) {

	}

	@Override
	protected Jnds getOneProject(Row row) {
		String year = ExcelUtil.formatCell(row.getCell(0));
		String classessStr = ExcelUtil.formatCell(row.getCell(1));
		String s = ExcelUtil.formatCell(row.getCell(2));
		String  award= ExcelUtil.formatCell(row.getCell(3));
		String projectName = ExcelUtil.formatCell(row.getCell(4));
		Jnds jxcg = new Jnds();
		jxcg.setDate(year);
		jxcg.setClassess(this.translateClassess(s));
		jxcg.setCategories(this.translateCategories(classessStr));
		jxcg.setAward(this.translateAward(award));
		jxcg.setProjectName(projectName);
		jxcg.setIsPass(0);
		//这个地方不要忘了-算总分
		jxcg.setTotalScore(this.getTotalScore(jxcg));
		return jxcg;
	}

	@Override
	public Double getTotalScore(Jnds jnds) {
		Integer categories = jnds.getCategories();
		Integer classess = jnds.getClassess();
		Integer award = jnds.getAward();
		double result = 300;
		if (categories == 1){
			if (classess == 1) {
				if (award == 1) {
				    result = 200;
				}else if (award == 2) {
					result = 150;
				}else if (award == 3) {
					result = 60;
				}
            }else if (classess == 2) {
				if (award == 1) {
					result = 50;
				}else if (award == 2) {
					result = 35;
				}else if (award == 3) {
					result = 20;
				}
            }
		}else if (categories == 2) {
			if (classess == 1) {
				if (award == 1) {
					result = 150;
				}else if (award == 2) {
					result = 60;
				}else if (award == 3) {
					result = 40;
				}
			}else if (classess == 2) {
				if (award == 1) {
					result = 30;
				}else if (award == 2) {
					result = 15;
				}else if (award == 3) {
					result = 5;
				}
			}
		}
		return result;

	}

	@Override
	public Page<JndsMemberPage> selectListPage(String date, int pageNum, int pageSize) {
		Page<JndsMemberPage> jgxmMemberPagePage = new Page<>(pageNum, pageSize);
		Page<JndsMemberPage> jgxmMemberPagePage1 = jgxmMemberPagePage.setRecords(baseMapper.selectJndsMemberPageListByYear(date));
		return jgxmMemberPagePage1;
	}

	@Override
	public List<JndsMemberPage> getMemberPageListByYear(String date) {
		return baseMapper.selectJndsMemberPageListByYear(date);
	}


	@Override
	protected List<TeachingResultContent> createTeachingResultContent(Jnds jxcg)  {

		List<TeachingResultContent> result = new ArrayList<>();

		// 类型
		TeachingResultContent classTeachingResultContent = new TeachingResultContent();
		classTeachingResultContent.setType(1);
		classTeachingResultContent.setLevel(jxcg.getClassess());

		try {
			classTeachingResultContent.setValue(dictTranslater.getDictValue(JndsMemberPage.class, "classess", String.valueOf(jxcg.getClassess())));
			result.add(classTeachingResultContent);
		} catch (NoSuchFieldException e) {
			log.error(e.getMessage(),e);
		}

		//奖项
		TeachingResultContent awardTeachingResultContent = new TeachingResultContent();
		awardTeachingResultContent.setType(1);
		awardTeachingResultContent.setLevel(jxcg.getAward());
		try {
			awardTeachingResultContent.setValue(dictTranslater.getDictValue(JndsMemberPage.class, "award", String.valueOf(jxcg.getAward())));
			result.add(awardTeachingResultContent);
		} catch (NoSuchFieldException e) {
			log.error(e.getMessage(),e);
		}

		return result;
	}


}
